package com.example.ercmssystem2.config;

import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;

/**
 * 统一状态配置类
 * 管理系统中所有状态的英文和中文对应关系
 */
@Component
public class StatusConfig {

    // 事件状态映射
    private static final Map<String, String> EVENT_STATUS_MAP = new HashMap<>();
    
    // 响应者状态映射
    private static final Map<String, String> RESPONDER_STATUS_MAP = new HashMap<>();
    
    // 用户状态映射
    private static final Map<String, String> USER_STATUS_MAP = new HashMap<>();
    
    // 资源状态映射
    private static final Map<String, String> RESOURCE_STATUS_MAP = new HashMap<>();
    
    // 安全状态映射
    private static final Map<String, String> SAFETY_STATUS_MAP = new HashMap<>();
    
    // 优先级映射
    private static final Map<String, String> PRIORITY_MAP = new HashMap<>();
    
    // 严重程度映射
    private static final Map<String, String> SEVERITY_MAP = new HashMap<>();
    
    // 状态颜色映射
    private static final Map<String, String> STATUS_COLOR_MAP = new HashMap<>();
    
    // 状态样式类映射
    private static final Map<String, String> STATUS_CLASS_MAP = new HashMap<>();

    static {
        // 初始化事件状态映射
        EVENT_STATUS_MAP.put("PENDING", "待处理");
        EVENT_STATUS_MAP.put("ASSIGNED", "已分配");
        EVENT_STATUS_MAP.put("IN_PROGRESS", "处理中");
        EVENT_STATUS_MAP.put("RESOLVED", "已解决");
        EVENT_STATUS_MAP.put("CLOSED", "已关闭");

        // 初始化响应者状态映射
        RESPONDER_STATUS_MAP.put("ASSIGNED", "已指派");
        RESPONDER_STATUS_MAP.put("ACCEPTED", "已接受");
        RESPONDER_STATUS_MAP.put("EN_ROUTE", "正在前往");
        RESPONDER_STATUS_MAP.put("ARRIVED", "到达现场");
        RESPONDER_STATUS_MAP.put("IN_PROGRESS", "开始处理");
        RESPONDER_STATUS_MAP.put("COMPLETED", "完成任务");
        RESPONDER_STATUS_MAP.put("RETURNING", "返程中");

        // 初始化用户状态映射
        USER_STATUS_MAP.put("AVAILABLE", "可用");
        USER_STATUS_MAP.put("BUSY", "忙碌");
        USER_STATUS_MAP.put("OFFLINE", "离线");

        // 初始化资源状态映射
        RESOURCE_STATUS_MAP.put("AVAILABLE", "可用");
        RESOURCE_STATUS_MAP.put("IN_USE", "使用中");
        RESOURCE_STATUS_MAP.put("MAINTENANCE", "维护中");
        RESOURCE_STATUS_MAP.put("RETIRED", "已报废");

        // 初始化安全状态映射
        SAFETY_STATUS_MAP.put("SAFE", "安全");
        SAFETY_STATUS_MAP.put("CAUTION", "注意");
        SAFETY_STATUS_MAP.put("DANGER", "危险");
        SAFETY_STATUS_MAP.put("SOS", "紧急求助");

        // 初始化优先级映射
        PRIORITY_MAP.put("LOW", "低");
        PRIORITY_MAP.put("MEDIUM", "中");
        PRIORITY_MAP.put("HIGH", "高");
        PRIORITY_MAP.put("CRITICAL", "危急");

        // 初始化严重程度映射
        SEVERITY_MAP.put("MINOR", "轻微");
        SEVERITY_MAP.put("MODERATE", "一般");
        SEVERITY_MAP.put("SEVERE", "严重");
        SEVERITY_MAP.put("CRITICAL", "危急");

        // 初始化状态颜色映射
        STATUS_COLOR_MAP.put("PENDING", "#ffc107");
        STATUS_COLOR_MAP.put("ASSIGNED", "#17a2b8");
        STATUS_COLOR_MAP.put("IN_PROGRESS", "#007bff");
        STATUS_COLOR_MAP.put("RESOLVED", "#28a745");
        STATUS_COLOR_MAP.put("CLOSED", "#6c757d");
        STATUS_COLOR_MAP.put("ACCEPTED", "#007bff");
        STATUS_COLOR_MAP.put("EN_ROUTE", "#007bff");
        STATUS_COLOR_MAP.put("ARRIVED", "#007bff");
        STATUS_COLOR_MAP.put("COMPLETED", "#28a745");
        STATUS_COLOR_MAP.put("RETURNING", "#28a745");
        STATUS_COLOR_MAP.put("AVAILABLE", "#28a745");
        STATUS_COLOR_MAP.put("BUSY", "#ffc107");
        STATUS_COLOR_MAP.put("OFFLINE", "#6c757d");
        STATUS_COLOR_MAP.put("IN_USE", "#007bff");
        STATUS_COLOR_MAP.put("MAINTENANCE", "#fd7e14");
        STATUS_COLOR_MAP.put("RETIRED", "#6c757d");
        STATUS_COLOR_MAP.put("SAFE", "#28a745");
        STATUS_COLOR_MAP.put("CAUTION", "#ffc107");
        STATUS_COLOR_MAP.put("DANGER", "#fd7e14");
        STATUS_COLOR_MAP.put("SOS", "#dc3545");

        // 初始化状态样式类映射
        STATUS_CLASS_MAP.put("PENDING", "bg-warning");
        STATUS_CLASS_MAP.put("ASSIGNED", "bg-info");
        STATUS_CLASS_MAP.put("IN_PROGRESS", "bg-primary");
        STATUS_CLASS_MAP.put("RESOLVED", "bg-success");
        STATUS_CLASS_MAP.put("CLOSED", "bg-secondary");
        STATUS_CLASS_MAP.put("ACCEPTED", "bg-primary");
        STATUS_CLASS_MAP.put("EN_ROUTE", "bg-primary");
        STATUS_CLASS_MAP.put("ARRIVED", "bg-primary");
        STATUS_CLASS_MAP.put("COMPLETED", "bg-success");
        STATUS_CLASS_MAP.put("RETURNING", "bg-success");
        STATUS_CLASS_MAP.put("AVAILABLE", "bg-success");
        STATUS_CLASS_MAP.put("BUSY", "bg-warning");
        STATUS_CLASS_MAP.put("OFFLINE", "bg-secondary");
        STATUS_CLASS_MAP.put("IN_USE", "bg-primary");
        STATUS_CLASS_MAP.put("MAINTENANCE", "bg-warning");
        STATUS_CLASS_MAP.put("RETIRED", "bg-secondary");
    }

    /**
     * 获取事件状态中文名称
     */
    public String getEventStatusText(String status) {
        return EVENT_STATUS_MAP.getOrDefault(status, status);
    }

    /**
     * 获取响应者状态中文名称
     */
    public String getResponderStatusText(String status) {
        return RESPONDER_STATUS_MAP.getOrDefault(status, status);
    }

    /**
     * 获取用户状态中文名称
     */
    public String getUserStatusText(String status) {
        return USER_STATUS_MAP.getOrDefault(status, status);
    }

    /**
     * 获取资源状态中文名称
     */
    public String getResourceStatusText(String status) {
        return RESOURCE_STATUS_MAP.getOrDefault(status, status);
    }

    /**
     * 获取安全状态中文名称
     */
    public String getSafetyStatusText(String status) {
        return SAFETY_STATUS_MAP.getOrDefault(status, status);
    }

    /**
     * 获取优先级中文名称
     */
    public String getPriorityText(String priority) {
        return PRIORITY_MAP.getOrDefault(priority, priority);
    }

    /**
     * 获取严重程度中文名称
     */
    public String getSeverityText(String severity) {
        return SEVERITY_MAP.getOrDefault(severity, severity);
    }

    /**
     * 获取状态颜色
     */
    public String getStatusColor(String status) {
        return STATUS_COLOR_MAP.getOrDefault(status, "#6c757d");
    }

    /**
     * 获取状态样式类
     */
    public String getStatusClass(String status) {
        return STATUS_CLASS_MAP.getOrDefault(status, "bg-secondary");
    }

    /**
     * 获取所有事件状态
     */
    public Map<String, String> getAllEventStatuses() {
        return new HashMap<>(EVENT_STATUS_MAP);
    }

    /**
     * 获取所有响应者状态
     */
    public Map<String, String> getAllResponderStatuses() {
        return new HashMap<>(RESPONDER_STATUS_MAP);
    }

    /**
     * 获取所有用户状态
     */
    public Map<String, String> getAllUserStatuses() {
        return new HashMap<>(USER_STATUS_MAP);
    }

    /**
     * 获取所有资源状态
     */
    public Map<String, String> getAllResourceStatuses() {
        return new HashMap<>(RESOURCE_STATUS_MAP);
    }

    /**
     * 获取所有安全状态
     */
    public Map<String, String> getAllSafetyStatuses() {
        return new HashMap<>(SAFETY_STATUS_MAP);
    }

    /**
     * 获取所有优先级
     */
    public Map<String, String> getAllPriorities() {
        return new HashMap<>(PRIORITY_MAP);
    }

    /**
     * 获取所有严重程度
     */
    public Map<String, String> getAllSeverities() {
        return new HashMap<>(SEVERITY_MAP);
    }

    /**
     * 验证事件状态是否有效
     */
    public boolean isValidEventStatus(String status) {
        return EVENT_STATUS_MAP.containsKey(status);
    }

    /**
     * 验证响应者状态是否有效
     */
    public boolean isValidResponderStatus(String status) {
        return RESPONDER_STATUS_MAP.containsKey(status);
    }

    /**
     * 验证用户状态是否有效
     */
    public boolean isValidUserStatus(String status) {
        return USER_STATUS_MAP.containsKey(status);
    }

    /**
     * 验证资源状态是否有效
     */
    public boolean isValidResourceStatus(String status) {
        return RESOURCE_STATUS_MAP.containsKey(status);
    }

    /**
     * 验证安全状态是否有效
     */
    public boolean isValidSafetyStatus(String status) {
        return SAFETY_STATUS_MAP.containsKey(status);
    }

    /**
     * 验证优先级是否有效
     */
    public boolean isValidPriority(String priority) {
        return PRIORITY_MAP.containsKey(priority);
    }

    /**
     * 验证严重程度是否有效
     */
    public boolean isValidSeverity(String severity) {
        return SEVERITY_MAP.containsKey(severity);
    }
} 